Page({
    data: {
         menuList:[],
         selectId:null,
         num:0
         
    },
    onLoad:function(opt){
       var userInfo= wx.getStorageSync('userInfo');
        this.setData({
            userInfo:userInfo,
            code:opt.code
        })
      this.getMents();
      this.getGoods();

    },
    onShow:function(){
       var searchMode= wx.getStorageSync('searchMode');
       // console.log()
       console.log('searchMode=='+searchMode)
       if (searchMode) {
        wx.setStorageSync('searchMode',null);
        this.getGoods2(searchMode)
       }
       // if (serc) {}
       this.getNum();
    },
    getMents:function(){
    var _self=this;
        wx.request({
            url:getApp().globalData.baseUrl+'/freight/activity/partsList?merchantId='+this.data.code,
            method:"get",
            header:{
               'openid':this.data.userInfo.openid, //公用请求头
               'content-type': 'application/json'
            },
            success: function(res) {
              if (res.data.code==200) {
                _self.setData({
                  goodsList:res.data.obj.list
                })
              }
            console.log(res)  
            
         }
       })
    },
    getNum:function(){
       var _self=this;
        wx.request({
            url:getApp().globalData.baseUrl+'/pj/shopping/find/num?openid='+this.data.userInfo.openid,
            method:"get",
            header:{
               'openid':this.data.userInfo.openid, //公用请求头
               'content-type': 'application/json'
            },
            success: function(res) {
              if (res.data.code==200) {
                _self.setData({
                  num:res.data.obj
                })
              }
            console.log(res)  
            
         }
       })


    },
    chooseType:function(e){
      console.log(e.currentTarget.dataset.id)
      this.setData({
        selectId:e.currentTarget.dataset.id
      })
      this.getGoods()
    },
    getGoods:function(){
       var _self=this;
        wx.request({
            url:getApp().globalData.baseUrl+'//freight/activity/details?merchantId='+this.data.code,
            method:"get",
            header:{
               'openid':this.data.userInfo.openid, //公用请求头
               'content-type': 'application/json'
            },
            success: function(res) {
              if (res.data.code==200) {
                _self.setData({
                    activity:res.data.obj
                })
              }
            console.log(res)  
            
         }
       })  
    },
    getGoods2:function(searchMode){
       var _self=this;
         wx.request({
            url:getApp().globalData.baseUrl+'/freight/activity/partsList?merchantId='+this.data.code+"&name="+searchMode,
            method:"get",
            header:{
               'openid':this.data.userInfo.openid, //公用请求头
               'content-type': 'application/json'
            },
            success: function(res) {
              if (res.data.code==200) {
                _self.setData({
                  goodsList:res.data.obj.list
                })
              }
            console.log(res)  
            
         }
       })
    },
    turnDetail:function(e){
        console.log(e);
        wx.navigateTo({
        url: '/pages/goodsDetail/goodsDetail?id='+e.currentTarget.dataset.code
      })
    },
    turnPage:function(){
       wx.navigateTo({
        url: '/pages/shopMarket/shopMarket'
      })
    },
    toSearch:function(){
       wx.navigateTo({
        url: '/pages/search/search'
      })
    }

});





